package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args){
        try(
                Connection connection = DBUtil.getConnection();
                ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT c.name,COUNT(*) FROM student s JOIN class c ON s.class_id= c.id GROUP BY c.name";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String className = rs.getString("name");
                int count = rs.getInt("COUNT(*)");
                System.out.println(className+"--"+count);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
